<?php
include("../../inc/conn.inc");
include("../islogin.php");
$url = $_POST['link_url'];
$name = $_POST['link_name'];
if($_POST['tj_act']=='sdibcn' && intval($_COOKIE['user_id'])>0)
{
	$url = str_replace('http://','',$url);
	$url = "http://".$url;
	$time = time();
	$sql = "insert into member_link(link_name,link_url,member_id,create_time) values ('$name','$url','".$_COOKIE['user_id']."','$time')";
	$re = mysql_query($sql);
	$query = mysql_query('SELECT * FROM `member_link` WHERE `member_id`<0');
	while($row = mysql_fetch_array($query)){
		
		mysql_query('DELETE  FROM `member_link` WHERE `id`='.$row['id']);
	}
	if($re)
	{
	echo '<script>alert("添加成功！");</script>';
	}

}

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>会员中心-三帝贸易网</title>
<link href="../css/css.css" rel="stylesheet" type="text/css" />
</head>
<script type="text/javascript" src="../js/left.js" charset="gb2312"></script>
<script type="text/javascript" src="../../js/jquery.js"></script>
<body>
<div id="mian">
<?php include("../inc/top.php");?>
<div class="top1"><span>您当前位置：<a href="../index.php" class="dh">会员助手</a> &gt;&gt; 企业网站 &gt;&gt; 友情链接</span></div>
<div class="left">
<?php include("../inc/left.php");?>
</div>
<div class="right">
<TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
   <TR>
     <TD height="40" bgcolor="#EFF6FF" style="font-size:18px;font-weight:bold;padding-left:8px;">添加友情链接</TD>
   </TR>
</TABLE>


<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#C1DCF5">
	  <form id="form1" method="post" action="" >
        <tr>
          <td height="35" colspan="2" align="center" bgcolor="#EFF6FF">添加友情链接</td>
        </tr>
        <tr>
          <td width="24%" height="35" align="center" bgcolor="#EFF6FF">友情链接名称</td>
          <td width="76%" bgcolor="#FFFFFF"><input name="link_name" id="link_name" type="text" size="30" maxlength="10">
          &nbsp;<font color="#999999">如：三帝贸易网</font></td>
		</tr>
        <tr>
          <td width="24%" height="35" align="center" bgcolor="#EFF6FF">友情链接网址</td>
          <td width="76%" bgcolor="#FFFFFF"><input name="link_url" id="link_url" type="text" size="30" >
          &nbsp;<font color="#999999">如：www.sandib2b.cn</font></td>
		</tr>
        <tr>
		  <td width="100%" colspan=2 height="35" align="left" bgcolor="#EFF6FF">
				<p style="margin-left:20%; line-height:26px;">温馨提醒：在本站添加友情链接前，请先在目标站添加上本站，等待我们的审核，<br />否则不予通过，请不要添加非法网站，谢谢您的合作。 </p></td>
        </tr>
        <tr>
          <td height="35" align="center" bgcolor="#EFF6FF">&nbsp;</td>
          <td bgcolor="#FFFFFF"><input type="submit" value="提交"></td>
        </tr><input type="hidden" name="tj_act" value="sdibcn">
		</form>
	</table>
</div>
<?php include("../inc/foot.php");?>

<script>

function IsURL(str_url){      
    var strRegex = "^((https|http|ftp|rtsp|mms)?://)"       
                    + "?(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-zA-Z_!~*'().&=+$%-]+@)?" //ftp的user@      
                    + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184      
                    + "|" // 允许IP和DOMAIN（域名）      
                    + "([0-9a-zA-Z_!~*'()-]+\.)*" // 域名- www.      
                    + "([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\." // 二级域名      
                    + "[a-zA-Z]{2,6})" // first level domain- .com or .museum      
                    + "(:[0-9]{1,4})?" // 端口- :80      
                    + "((/?)|"       
                    + "(/[0-9a-zA-Z_!~*'().;?:@&=+$,%#-]+)+/?)$";      
    var re=new RegExp(strRegex);      
    return re.test(str_url);      
}   



$(function()
	{
		$("#form1").submit(function()
			{
				var name = $("#link_name").val();
				var url = $("#link_url").val();
				if(name.length<2 || name.length>10)
				{
					alert("友情链接名称最少2个字符，最多10个字符");
				}
				else if(!IsURL(url))
				{
					alert("友情链接地址输入错误");
				}
				else
				{
					return true;
				}
				return false;

			});
	});	
</script>

</body>
</html>
